<template>
  <div>
    <el-upload
      v-bind="{ ...item }"
      :accept="(item.accept || []).join(',')"
      :action="item.action"
      :before-upload="beforeUpload"
      :file-list="fileList"
      :on-preview="handlePreview"
      :on-remove="handleRemove"
      :on-success="uploadSuccess"
      :on-exceed="handleExceed"
    >
      <i v-if="item.config['list-type'] === 'picture-card'" class="el-icon-plus" />
      <el-button v-else icon="el-icon-upload" size="small" type="primary">
        {{ item.config.buttonText }}
      </el-button>
      <div v-if="item.config.showTip" slot="tip" class="el-upload__tip">
        只能上传不超过 {{ item.config.fileSize }}{{ item.config.sizeUnit }}的{{
          (item.accept || []).join(',')
        }}文件,最多不超过{{ item.limit }}个文件
      </div>
    </el-upload>
  </div>
</template>

<script>
import uploadMixin from '../uploadMixin'

export default {
  name: 'TUpload',
  mixins: [uploadMixin],
  methods: {
    handlePreview(file) {
      window.open(file.url)
    }
  }
}
</script>

<style scoped></style>
